uniform sampler2D texturemap;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;

varying vec2 vUv;

void main() {
  vec4 blend = texture2D(texturemap, vUv);
  float baseWeight = 1.0 - max(blend.r, max(blend.g, blend.b));
  vec4 base = baseWeight * texture2D(texture1, vUv * 10.0);
  vec4 grass = blend.r * texture2D(texture1, vUv * 10.0);
  vec4 sand = blend.g * texture2D(texture2, vUv * 20.0);
  vec4 rock = blend.b * texture2D(texture3, vUv * 10.0);
  gl_FragColor = (vec4(0.0, 0.0, 0.0, 1.0) + base + grass + sand + rock) /
                 (baseWeight + blend.r + blend.g + blend.b);

  #include <alphatest_fragment>
  #include <logdepthbuf_fragment>

  #include <fog_fragment>
}
